$(function(){
	
});

var r = /^\+?[1-9][0-9]*$/;
function checkData(){
	//获取表单信息
	var meterId = $("#meterId").val();
	var modelCode = $("#modelCode").val();
	var useFor = $("#useFor").val();
	var usedAmount= $("#usedAmount").val();
	var usedTime = $("#usedTime").val();
	var avaliablAmount = $("#avaliablAmount").val();
	if (modelCode == "" || modelCode == null || modelCode  == "undefined") {
		msgFeedBack("部品番号不能为空","#modelCode");
		return false;
	}
	if (usedAmount == "" || usedAmount == null || usedAmount  == "undefined") {
		msgFeedBack("使用数量不能为空","#usedAmount");
		return false;
	}else if(!r.test(usedAmount)){
		msgFeedBack("请输入正整数","#usedAmount");
		return false;
	}else if(Number(usedAmount)>Number(avaliablAmount)){
		msgFeedBack("材料不足","#usedAmount");
		return false;
	}
	if (usedTime == "" || usedTime == null || usedTime  == "undefined") {
		msgFeedBack("使用时间不能为空","#usedTime");
		return false;
	}
	
	return true
} 

function saveMeterUsed(status){
	if(checkData()){
	//获取表单信息
		var meterPlanId = $("#meterId").val();
		var modelCode = $("#modelCode").val();
		var useFor = $("#useFor").val();
		var usedAmount= $("#usedAmount").val();
		var usedTime = $("#usedTime").val();
	var pcoResult = [];
	var data = {
			id : meterPlanId,
			modelCode : modelCode,
			useFor : useFor,
			usedAmount : usedAmount,
			usedTime : usedTime,
			status : status
		};
	pcoResult.push(data);
	var url = basePath+"/bus/progress/usedMeterEdit";
	showLoad();
		$.ajax({
			type : "post",
			url : url,
			data : {pcoData:JSON.stringify(pcoResult)},
			dataType : "json",
			success : function(data) {
				msgPrompt(data.message);
                window.location.href=basePath+"/bus/progress/toMeterUseView?modelCode=" + modelCode;
			}
		});
	}
}
//页面跳转
function toIndex(){
	var url = basePath+"/bus/meter/meterGiveList";
	window.location.href=url;
}
